package com.netease.nie.common;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.netease.nie.base.cdn.CDNProperties;
import com.netease.nie.base.exceptions.BusinessException;
import com.netease.nie.base.utils.CopyUtils;
import com.netease.nie.base.utils.CustomDateFormatUtils;
import com.netease.nie.base.utils.DateUtils;
import com.netease.nie.constants.BusinessConstants;
import com.netease.nie.constants.CachePrefixConstants;
import com.netease.nie.constants.DisplayTypeConstants;
import com.netease.nie.dto.BannerDto;
import com.netease.nie.dto.ColumnGoodsSnapshotDto;
import com.netease.nie.dto.DrawLotteryGoodsPrizeBaseInfoDto;
import com.netease.nie.dto.ExchangeGoodsExchangeDto;
import com.netease.nie.dto.ExchangeGoodsInfoListDto;
import com.netease.nie.dto.GoodsInfoImageDto;
import com.netease.nie.dto.LimitedTimeExchangeDto;
import com.netease.nie.dto.MyExchangeDto;
import com.netease.nie.dto.MyLuckyPrizeDto;
import com.netease.nie.dto.MyRobGoodsPrizeTipsDto;
import com.netease.nie.dto.RobGoodsPeriodUserPersonTimeDto;
import com.netease.nie.dto.RobGoodsPrizeBaseInfoDto;
import com.netease.nie.dto.RobGoodsSnapshotDto;
import com.netease.nie.dto.RobbedGoodsDto;
import com.netease.nie.dto.TopicDetailDto;
import com.netease.nie.dto.TopicDetailDto.CustomGoodsDto;
import com.netease.nie.dto.TopicSnapshotDto;
import com.netease.nie.model.Banner;
import com.netease.nie.model.ColumnInfo;
import com.netease.nie.model.ExchangeGoodsInfo;
import com.netease.nie.model.TopicDto;

/**
 * 
 * @author wwbn3695
 * @createDate June 24th,2016
 *
 */
public abstract class CommonBusinessTools {

	@Autowired
	private CDNProperties cdnProperties;
	
	protected void computeRemainDays(ExchangeGoodsInfoListDto goodsInfoListDto) {
		long currTimeMills = DateUtils.currentTimeInMills();
		if (goodsInfoListDto == null)
			throw new BusinessException(BusinessConstants.GOODS_NOT_EXISTS.getCode(), "商品不存在");
		Long putOffTime = goodsInfoListDto.getPutOffTime();
		int remainDays = 0;
		if (putOffTime != null) {
			remainDays = DateUtils.daysBetween(currTimeMills, goodsInfoListDto.getPutOffTime());
			goodsInfoListDto.setRemainDays(remainDays);
		}
	}
	
	protected Map<Integer, Integer> distillGoodsStock(String[] exchangeGoodsStockKeys, List<String> strList) {
		String stockTemp = null;
		if (strList != null && !strList.isEmpty()) {
			Map<Integer, Integer> goodsStockMap = new HashMap<>();
			int strListSize = strList.size();
			for (int i = 0; i < strListSize; i++) {
				stockTemp = strList.get(i);
				if (StringUtils.isNotBlank(stockTemp)) {
					int id = Integer.valueOf(StringUtils.removeStart(exchangeGoodsStockKeys[i], CachePrefixConstants.GoodsPrefix.GOODS_STOCK_PREFIX));
					goodsStockMap.put(id, Integer.valueOf(stockTemp));
				}
			}
			return goodsStockMap;
		}
		return Collections.emptyMap();
	}
	
	protected Map<Integer, List<ExchangeGoodsInfoListDto>> transferCoGoodsListDtos(List<ExchangeGoodsInfoListDto> exchangeGoodsInfoListDtos) {
		if (exchangeGoodsInfoListDtos != null && !exchangeGoodsInfoListDtos.isEmpty()) {
			Map<Integer, List<ExchangeGoodsInfoListDto>> map = new HashMap<>();
			ExchangeGoodsInfoListDto exchangeGoodsInfoListDto = null;
			List<ExchangeGoodsInfoListDto> exchangeGoodsInfoListDtoTemps = null;
			int exchangeGoodsInfoListDtosSize = exchangeGoodsInfoListDtos.size();
			for (int i = 0; i < exchangeGoodsInfoListDtosSize; i++) {
				exchangeGoodsInfoListDto = exchangeGoodsInfoListDtos.get(i);
				int columnId = exchangeGoodsInfoListDto.getColumnId();
				if (map.containsKey(columnId)) {
					exchangeGoodsInfoListDtoTemps = map.get(columnId);
				} else {
					exchangeGoodsInfoListDtoTemps = new ArrayList<>();
				}
				exchangeGoodsInfoListDtoTemps.add(exchangeGoodsInfoListDto);
				map.put(columnId, exchangeGoodsInfoListDtoTemps);
			}
			return map;
		}
		return Collections.emptyMap();
	}
	
	protected void replaceGoodsInfoListDtoThumbnailUrl(List<ExchangeGoodsInfoListDto> exchangeGoodsInfoListDtos, int origin) {
		if (exchangeGoodsInfoListDtos != null && !exchangeGoodsInfoListDtos.isEmpty()) {
			int goodsInfoListDtosSize = exchangeGoodsInfoListDtos.size();
			ExchangeGoodsInfoListDto exchangeGoodsInfoListDto = null;
			for (int i = 0; i < goodsInfoListDtosSize; i++) {
				exchangeGoodsInfoListDto = exchangeGoodsInfoListDtos.get(i);
				if (origin == DisplayTypeConstants.WAP.getCode()) {
					if (StringUtils.isNotBlank(exchangeGoodsInfoListDto.getThumbnailWapUrl()))
						exchangeGoodsInfoListDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + exchangeGoodsInfoListDto.getThumbnailWapUrl());
				} else if (origin == DisplayTypeConstants.WEB.getCode()) {
					if (StringUtils.isNotBlank(exchangeGoodsInfoListDto.getThumbnailWebUrl()))
						exchangeGoodsInfoListDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + exchangeGoodsInfoListDto.getThumbnailWebUrl());
				}
			}
		}
	}
	
	protected Map<Integer, List<ExchangeGoodsInfoListDto>> transferCaGoodsListDtos(List<ExchangeGoodsInfoListDto> exchangeGoodsInfoListDtos) {
		if (exchangeGoodsInfoListDtos != null && !exchangeGoodsInfoListDtos.isEmpty()) {
			Map<Integer, List<ExchangeGoodsInfoListDto>> map = new HashMap<>();
			ExchangeGoodsInfoListDto exchangeGoodsInfoListDto = null;
			List<ExchangeGoodsInfoListDto> exchangeGoodsInfoListDtoTemps = null;
			int goodsInfoListDtosSize = exchangeGoodsInfoListDtos.size();
			for (int i = 0; i < goodsInfoListDtosSize; i++) {
				exchangeGoodsInfoListDto = exchangeGoodsInfoListDtos.get(i);
				int categoryId = exchangeGoodsInfoListDto.getCategoryId();
				if (map.containsKey(categoryId)) {
					exchangeGoodsInfoListDtoTemps = map.get(categoryId);
				} else {
					exchangeGoodsInfoListDtoTemps = new ArrayList<>();
				}
				exchangeGoodsInfoListDtoTemps.add(exchangeGoodsInfoListDto);
				map.put(categoryId, exchangeGoodsInfoListDtoTemps);
			}
			return map;
		}
		return Collections.emptyMap();
	}
	
	protected List<BannerDto> generateBannerDtoList(List<Banner> bannerList, int origin) {
		Banner banner = null;
		BannerDto bannerDto = null;
		int size = bannerList.size();
		List<BannerDto> bannerDtoList = new ArrayList<>();
		for (int i = 0; i < size; i++) {
			banner = bannerList.get(i);
			bannerDto = new BannerDto();
			CopyUtils.copy(bannerDto, banner);
			if (origin == DisplayTypeConstants.WAP.getCode()) {
				if (StringUtils.isNotBlank(banner.getCoverWapUrl()))
					bannerDto.setCoverUrl(cdnProperties.getCdnPrefix() + banner.getCoverWapUrl());
			} else if (origin == DisplayTypeConstants.WEB.getCode()) {
				if (StringUtils.isNotBlank(banner.getCoverWebUrl()))
					bannerDto.setCoverUrl(cdnProperties.getCdnPrefix() + banner.getCoverWebUrl());
			}
			bannerDtoList.add(bannerDto);
		}
		return bannerDtoList;
	}
	
	protected void fillColunInfo2ListColumnGoodsSnapshotDtoList(List<ColumnGoodsSnapshotDto> columnGoodsSnapshotDtos, List<ColumnInfo> columnInfoList, int origin) {
		if (columnInfoList != null && !columnInfoList.isEmpty()) {
			ColumnInfo columnInfo = null;
			ColumnGoodsSnapshotDto columnGoodsSnapshotDto = null;
			int columnInfoListSize = columnInfoList.size();
			for (int i = 0; i < columnInfoListSize; i++) {
				columnInfo = columnInfoList.get(i);
				columnGoodsSnapshotDto = new ColumnGoodsSnapshotDto();
				columnGoodsSnapshotDto.setId(columnInfo.getId());
				if (columnInfo.getIsDisplayTitle() == 1)
					columnGoodsSnapshotDto.setTitle(columnInfo.getTitle());
				if (origin == DisplayTypeConstants.WAP.getCode()) {
					if (StringUtils.isNotBlank(columnInfo.getCoverWapUrl()))
						columnGoodsSnapshotDto.setCoverUrl(cdnProperties.getCdnPrefix() + columnInfo.getCoverWapUrl());
				} else if (origin == DisplayTypeConstants.WEB.getCode()) {
					if (StringUtils.isNotBlank(columnInfo.getCoverWebUrl()))
						columnGoodsSnapshotDto.setCoverUrl(cdnProperties.getCdnPrefix() + columnInfo.getCoverWebUrl());
				}
				columnGoodsSnapshotDtos.add(columnGoodsSnapshotDto);
			}
		}
	}
	
	protected void replaceGoodsInfoImageDto(List<GoodsInfoImageDto> goodsInfoImageDtos, int origin) {
		if (goodsInfoImageDtos != null && !goodsInfoImageDtos.isEmpty()) {
			int goodsInfoImageDtosSize = goodsInfoImageDtos.size();
			GoodsInfoImageDto goodsInfoImageDto = null;
			for (int i = 0; i < goodsInfoImageDtosSize; i++) {
				goodsInfoImageDto = goodsInfoImageDtos.get(i);
				if (origin == DisplayTypeConstants.WAP.getCode()) {
					if (StringUtils.isNotBlank(goodsInfoImageDto.getImageWapUrl()))
						goodsInfoImageDto.setImageUrl(cdnProperties.getCdnPrefix() + goodsInfoImageDto.getImageWapUrl());
				} else if (origin == DisplayTypeConstants.WEB.getCode()) {
					if (StringUtils.isNotBlank(goodsInfoImageDto.getImageWebUrl()))
						goodsInfoImageDto.setImageUrl(cdnProperties.getCdnPrefix() + goodsInfoImageDto.getImageWebUrl());
				}
				goodsInfoImageDto.setImageWapUrl(null);
				goodsInfoImageDto.setImageWebUrl(null);
			}
		}
	}
	
	protected void replaceThumbnailUrlInMyExchangeDto(List<MyExchangeDto> myExchangeDtoList, int origin) {
		if (myExchangeDtoList != null && !myExchangeDtoList.isEmpty()) {
			int myExchangeCodeDtoListSize = myExchangeDtoList.size();
			MyExchangeDto myExchangeDto = null;
			for (int i = 0; i < myExchangeCodeDtoListSize; ++i) {
				myExchangeDto = myExchangeDtoList.get(i);
				if (origin == DisplayTypeConstants.WAP.getCode()) {
					if (StringUtils.isNotBlank(myExchangeDto.getThumbnailWapUrl()))
						myExchangeDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + myExchangeDto.getThumbnailWapUrl());
				} else if (origin == DisplayTypeConstants.WEB.getCode()) {
					if (StringUtils.isNotBlank(myExchangeDto.getThumbnailWebUrl()))
						myExchangeDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + myExchangeDto.getThumbnailWebUrl());
				}
				myExchangeDto.setThumbnailWapUrl(null);
				myExchangeDto.setThumbnailWebUrl(null);
			}
		}
	}
	
	protected void replaceGoodsExchangeDto(ExchangeGoodsExchangeDto exchangeGoodsExchangeDto, int origin) {
		if (origin == DisplayTypeConstants.WAP.getCode()) {
			if (StringUtils.isNotBlank(exchangeGoodsExchangeDto.getImageWapUrl()))
				exchangeGoodsExchangeDto.setCoverUrl(cdnProperties.getCdnPrefix() + exchangeGoodsExchangeDto.getImageWapUrl());
		} else if (origin == DisplayTypeConstants.WEB.getCode()) {
			if (StringUtils.isNotBlank(exchangeGoodsExchangeDto.getImageWebUrl()))
				exchangeGoodsExchangeDto.setCoverUrl(cdnProperties.getCdnPrefix() + exchangeGoodsExchangeDto.getImageWebUrl());
		}
		exchangeGoodsExchangeDto.setImageWapUrl(null);
		exchangeGoodsExchangeDto.setImageWebUrl(null);
	}
	
	protected void replaceLimitedTimeExchangeDtoThumbnailUrl(LimitedTimeExchangeDto limitedTimeExchangeDto, int origin) {
		if (origin == DisplayTypeConstants.WAP.getCode()) {
			if (StringUtils.isNotBlank(limitedTimeExchangeDto.getThumbnailWapUrl()))
				limitedTimeExchangeDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + limitedTimeExchangeDto.getThumbnailWapUrl());
		} else if (origin == DisplayTypeConstants.WEB.getCode()) {
			if (StringUtils.isNotBlank(limitedTimeExchangeDto.getThumbnailWebUrl()))
				limitedTimeExchangeDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + limitedTimeExchangeDto.getThumbnailWebUrl());
		}
		limitedTimeExchangeDto.setThumbnailWapUrl(null);
		limitedTimeExchangeDto.setThumbnailWebUrl(null);
	}
	
	protected void replaceRobGoodsSnapshotDtoThumbnailUrl(List<RobGoodsSnapshotDto> robGoodsSnapshotDtos, int origin) {
		if (robGoodsSnapshotDtos != null && !robGoodsSnapshotDtos.isEmpty()) {
			int robGoodsSnapshotDtosSize = robGoodsSnapshotDtos.size();
			RobGoodsSnapshotDto robGoodsSnapshotDto = null;
			for (int i = 0; i < robGoodsSnapshotDtosSize; i++) {
				robGoodsSnapshotDto = robGoodsSnapshotDtos.get(i);
				if (origin == DisplayTypeConstants.WAP.getCode()) {
					if (StringUtils.isNotBlank(robGoodsSnapshotDto.getThumbnailWapUrl()))
						robGoodsSnapshotDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + robGoodsSnapshotDto.getThumbnailWapUrl());
				} else if (origin == DisplayTypeConstants.WEB.getCode()) {
					if (StringUtils.isNotBlank(robGoodsSnapshotDto.getThumbnailWebUrl()))
						robGoodsSnapshotDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + robGoodsSnapshotDto.getThumbnailWebUrl());
				}
				robGoodsSnapshotDto.setThumbnailWapUrl(null);
				robGoodsSnapshotDto.setThumbnailWebUrl(null);
			}
		}
	}
	
	protected void replaceMyLuckyPrizeDtoThumbnailUrl(List<MyLuckyPrizeDto> myLuckyPrizeDtos, int origin) {
		if (myLuckyPrizeDtos != null && !myLuckyPrizeDtos.isEmpty()) {
			int myLuckyPrizeDtosSize = myLuckyPrizeDtos.size();
			MyLuckyPrizeDto myLuckyPrizeDto = null;
			for (int i = 0; i < myLuckyPrizeDtosSize; i++) {
				myLuckyPrizeDto = myLuckyPrizeDtos.get(i);
				if (origin == DisplayTypeConstants.WAP.getCode()) {
					if (StringUtils.isNotBlank(myLuckyPrizeDto.getThumbnailWapUrl()))
						myLuckyPrizeDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + myLuckyPrizeDto.getThumbnailWapUrl());
				} else if (origin == DisplayTypeConstants.WEB.getCode()) {
					if (StringUtils.isNotBlank(myLuckyPrizeDto.getThumbnailWebUrl()))
						myLuckyPrizeDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + myLuckyPrizeDto.getThumbnailWebUrl());
				}
				myLuckyPrizeDto.setThumbnailWapUrl(null);
				myLuckyPrizeDto.setThumbnailWebUrl(null);
			}
		}
	}
	
	protected Map<Integer, RobGoodsPeriodUserPersonTimeDto> generateRobUserPtAndNumberMap(List<RobGoodsPeriodUserPersonTimeDto> robGoodsPeriodUserPersonTimeDtoList) {
		if (robGoodsPeriodUserPersonTimeDtoList != null && !robGoodsPeriodUserPersonTimeDtoList.isEmpty()) {
			RobGoodsPeriodUserPersonTimeDto tempRobGoodsPeriodUserPersonTimeDto = null, robGoodsPeriodUserPersonTimeDto = null;
			Map<Integer, RobGoodsPeriodUserPersonTimeDto> robUserPtAndNumberMap = new HashMap<>();
			int robGoodsPeriodUserPersonTimeDtoListSize = robGoodsPeriodUserPersonTimeDtoList.size();
			for (int i = 0; i < robGoodsPeriodUserPersonTimeDtoListSize; i++) {
				tempRobGoodsPeriodUserPersonTimeDto = robGoodsPeriodUserPersonTimeDtoList.get(i);
				int robUserPt = 0;
				StringBuilder userNumberBuilder = new StringBuilder();
				String tempUserNumber;
				int robGoodsPeriodId = tempRobGoodsPeriodUserPersonTimeDto.getPeriodId();
				if (robUserPtAndNumberMap.containsKey(robGoodsPeriodId)) {
					robGoodsPeriodUserPersonTimeDto = robUserPtAndNumberMap.get(robGoodsPeriodId);
					robUserPt = robGoodsPeriodUserPersonTimeDto.getRobUserPt();
					tempUserNumber = robGoodsPeriodUserPersonTimeDto.getRobUserNumber();
					userNumberBuilder.append(tempUserNumber).append(",").append(tempRobGoodsPeriodUserPersonTimeDto.getRobUserNumber());
				} else {
					robGoodsPeriodUserPersonTimeDto = new RobGoodsPeriodUserPersonTimeDto();
					userNumberBuilder.append(tempRobGoodsPeriodUserPersonTimeDto.getRobUserNumber());
				}
				
				robUserPt += tempRobGoodsPeriodUserPersonTimeDto.getRobUserPt();
				robGoodsPeriodUserPersonTimeDto.setRobUserPt(robUserPt);
				robGoodsPeriodUserPersonTimeDto.setRobUserNumber(userNumberBuilder.toString());
				robUserPtAndNumberMap.put(robGoodsPeriodId, robGoodsPeriodUserPersonTimeDto);
			}
			return robUserPtAndNumberMap;
		}
		return Collections.emptyMap();
	}
	
	protected Map<Integer, RobGoodsPeriodUserPersonTimeDto> generateRobUserDisplayPeriodPtMap(List<RobGoodsPeriodUserPersonTimeDto> robGoodsPeriodUserPersonTimeDtoList) {
		if (robGoodsPeriodUserPersonTimeDtoList != null && !robGoodsPeriodUserPersonTimeDtoList.isEmpty()) {
			RobGoodsPeriodUserPersonTimeDto tempRobGoodsPeriodUserPersonTimeDto = null, robGoodsPeriodUserPersonTimeDto = null;
			Map<Integer, RobGoodsPeriodUserPersonTimeDto> robUserDisplayPeriodPtMap = new HashMap<>();
			int robGoodsPeriodUserPersonTimeDtoListSize = robGoodsPeriodUserPersonTimeDtoList.size();
			for (int i = 0; i < robGoodsPeriodUserPersonTimeDtoListSize; i++) {
				tempRobGoodsPeriodUserPersonTimeDto = robGoodsPeriodUserPersonTimeDtoList.get(i);
				int robGoodsPeriodId = tempRobGoodsPeriodUserPersonTimeDto.getPeriodId();
				if (robUserDisplayPeriodPtMap.containsKey(robGoodsPeriodId)) {
					robGoodsPeriodUserPersonTimeDto = robUserDisplayPeriodPtMap.get(robGoodsPeriodId);
					int robUserPt = tempRobGoodsPeriodUserPersonTimeDto.getRobUserPt();
					robGoodsPeriodUserPersonTimeDto.setRobUserPt(robUserPt + robGoodsPeriodUserPersonTimeDto.getRobUserPt());
				} else {
					robGoodsPeriodUserPersonTimeDto = new RobGoodsPeriodUserPersonTimeDto();
					robGoodsPeriodUserPersonTimeDto.setDisplayPeriod(tempRobGoodsPeriodUserPersonTimeDto.getDisplayPeriod());
					robGoodsPeriodUserPersonTimeDto.setRobUserPt(tempRobGoodsPeriodUserPersonTimeDto.getRobUserPt());
				}
				robUserDisplayPeriodPtMap.put(robGoodsPeriodId, robGoodsPeriodUserPersonTimeDto);
			}
			return robUserDisplayPeriodPtMap;
		}
		return Collections.emptyMap();
	}
	
	protected void replaceTopicSnapshotDtoCoverUrl(List<TopicSnapshotDto> topicSnapshotDtoList, int origin) {
		if (topicSnapshotDtoList != null && !topicSnapshotDtoList.isEmpty()) {
			int topicSnapshotDtoListSize = topicSnapshotDtoList.size();
			TopicSnapshotDto topicSnapshotDto = null;
			for (int i = 0; i < topicSnapshotDtoListSize; i++) {
				topicSnapshotDto = topicSnapshotDtoList.get(i);
				if (origin == DisplayTypeConstants.WAP.getCode()) {
					if (StringUtils.isNotBlank(topicSnapshotDto.getCoverWapUrl()))
						topicSnapshotDto.setCoverUrl(cdnProperties.getCdnPrefix() + topicSnapshotDto.getCoverWapUrl());
				} else if (origin == DisplayTypeConstants.WEB.getCode()) {
					if (StringUtils.isNotBlank(topicSnapshotDto.getCoverWebUrl()))
						topicSnapshotDto.setCoverUrl(cdnProperties.getCdnPrefix() + topicSnapshotDto.getCoverWebUrl());
				}
				topicSnapshotDto.setCoverWapUrl(null);
				topicSnapshotDto.setCoverWebUrl(null);
			}
		}
	}
	
	protected void replaceRobGoodsPrizeBaseInfoDto(RobGoodsPrizeBaseInfoDto robGoodsPrizeBaseInfoDto, int origin) {
		if (origin == DisplayTypeConstants.WAP.getCode()) {
			if (StringUtils.isNotBlank(robGoodsPrizeBaseInfoDto.getThumbnailWapUrl()))
				robGoodsPrizeBaseInfoDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + robGoodsPrizeBaseInfoDto.getThumbnailWapUrl());
		} else if (origin == DisplayTypeConstants.WEB.getCode()) {
			if (StringUtils.isNotBlank(robGoodsPrizeBaseInfoDto.getThumbnailWebUrl()))
				robGoodsPrizeBaseInfoDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + robGoodsPrizeBaseInfoDto.getThumbnailWebUrl());
		}
		robGoodsPrizeBaseInfoDto.setThumbnailWapUrl(null);
		robGoodsPrizeBaseInfoDto.setThumbnailWebUrl(null);
	}
	
	protected void replaceDrawLotteryGoodsPrizeBaseInfoDto(DrawLotteryGoodsPrizeBaseInfoDto drawLotteryGoodsPrizeBaseInfoDto, int origin) {
		if (origin == DisplayTypeConstants.WAP.getCode()) {
			if (StringUtils.isNotBlank(drawLotteryGoodsPrizeBaseInfoDto.getThumbnailWapUrl()))
				drawLotteryGoodsPrizeBaseInfoDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + drawLotteryGoodsPrizeBaseInfoDto.getThumbnailWapUrl());
		} else if (origin == DisplayTypeConstants.WEB.getCode()) {
			if (StringUtils.isNotBlank(drawLotteryGoodsPrizeBaseInfoDto.getThumbnailWebUrl()))
				drawLotteryGoodsPrizeBaseInfoDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + drawLotteryGoodsPrizeBaseInfoDto.getThumbnailWebUrl());
		}
		drawLotteryGoodsPrizeBaseInfoDto.setThumbnailWapUrl(null);
		drawLotteryGoodsPrizeBaseInfoDto.setThumbnailWebUrl(null);
	}
	
	protected void replaceCustomGoodsDtoThumbnailUrl(List<CustomGoodsDto> customGoodsDtoList, int origin) {
		if (customGoodsDtoList != null && !customGoodsDtoList.isEmpty()) {
			int customGoodsDtoListSize = customGoodsDtoList.size();
			CustomGoodsDto customGoodsDto = null;
			for (int i = 0; i < customGoodsDtoListSize; i++) {
				customGoodsDto = customGoodsDtoList.get(i);
				if (origin == DisplayTypeConstants.WAP.getCode()) {
					if (StringUtils.isNotBlank(customGoodsDto.getThumbnailWapUrl()))
						customGoodsDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + customGoodsDto.getThumbnailWapUrl());
				} else if (origin == DisplayTypeConstants.WEB.getCode()) {
					if (StringUtils.isNotBlank(customGoodsDto.getThumbnailWebUrl()))
						customGoodsDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + customGoodsDto.getThumbnailWebUrl());
				}
				customGoodsDto.setThumbnailWapUrl(null);
				customGoodsDto.setThumbnailWebUrl(null);
			}
		}
	}
	
	protected void generateTopicDetailDtoCoverUrl(TopicDetailDto topicDetailDto, TopicDto topicDto, int origin) {
		if (origin == DisplayTypeConstants.WAP.getCode()) 
			topicDetailDto.setCoverUrl(cdnProperties.getCdnPrefix() + topicDto.getCoverWapUrl());
		else if (origin == DisplayTypeConstants.WEB.getCode())
			topicDetailDto.setCoverUrl(cdnProperties.getCdnPrefix() + topicDto.getCoverWebUrl());
	}
	
	protected void replaceRobbedGoodsDtoThumbnailUrl(List<RobbedGoodsDto> robbedGoodsDtoList, int origin) {
		if (robbedGoodsDtoList != null && !robbedGoodsDtoList.isEmpty()) {
			int robbedGoodsDtoListSize = robbedGoodsDtoList.size();
			RobbedGoodsDto robbedGoodsDto = null;
			for (int i = 0; i < robbedGoodsDtoListSize; i++) {
				robbedGoodsDto = robbedGoodsDtoList.get(i);
				if (origin == DisplayTypeConstants.WAP.getCode()) {
					if (StringUtils.isNotBlank(robbedGoodsDto.getThumbnailWapUrl()))
						robbedGoodsDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + robbedGoodsDto.getThumbnailWapUrl());
				} else if (origin == DisplayTypeConstants.WEB.getCode()) {
					if (StringUtils.isNotBlank(robbedGoodsDto.getThumbnailWebUrl()))
						robbedGoodsDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + robbedGoodsDto.getThumbnailWebUrl());
				}
				robbedGoodsDto.setThumbnailWapUrl(null);
				robbedGoodsDto.setThumbnailWebUrl(null);
			}
		}
	}
	
	protected void replaceMyRobGoodsPrizeTipsDtoThumbnailUrl(MyRobGoodsPrizeTipsDto myRobGoodsPrizeTipsDto, int origin) {
		if (myRobGoodsPrizeTipsDto != null) {
			if (origin == DisplayTypeConstants.WAP.getCode()) {
				if (StringUtils.isNotBlank(myRobGoodsPrizeTipsDto.getThumbnailWapUrl()))
					myRobGoodsPrizeTipsDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + myRobGoodsPrizeTipsDto.getThumbnailWapUrl());
			} else if (origin == DisplayTypeConstants.WEB.getCode()) {
				if (StringUtils.isNotBlank(myRobGoodsPrizeTipsDto.getThumbnailWebUrl()))
					myRobGoodsPrizeTipsDto.setThumbnailUrl(cdnProperties.getCdnPrefix() + myRobGoodsPrizeTipsDto.getThumbnailWebUrl());
			}
			myRobGoodsPrizeTipsDto.setThumbnailWapUrl(null);
			myRobGoodsPrizeTipsDto.setThumbnailWebUrl(null);
		}
	}
	
	/**
	 * 计算过期时间
	 * @param exchangeGoodsInfo	商品信息
	 * @param generateDate	兑换时间
	 * @return
	 */
	protected String computeExpireTime(ExchangeGoodsInfo exchangeGoodsInfo, Integer generateDate) {
		String expireDate = "";
		Integer fixedValidDate = exchangeGoodsInfo.getFixedValidDate();
		Integer changeableValidDate = exchangeGoodsInfo.getChangeableValidDate();
		if (fixedValidDate != null)
			expireDate = CustomDateFormatUtils.getyyyyMMddStr(fixedValidDate);
		else if (changeableValidDate != null) {
			LocalDate expireTime = LocalDate.ofEpochDay(generateDate).plusDays(changeableValidDate);
			expireDate = CustomDateFormatUtils.getyyyyMMddStr(expireTime.toEpochDay());
		}
		
		return expireDate;
	}
}
